//
//  MainTableBarViewController.m
//  Maylida
//
//  Created by laojingxing on 2017/9/5.
//  Copyright © 2017年 laojingxing. All rights reserved.
//

#import "MainTableBarViewController.h"
#import "BaseNavViewController.h"
#import "HomePageViewController.h"
#import "DiscoveryViewController.h"
#import "NewsViewController.h"
#import "MineViewController.h"


@interface MainTableBarViewController ()

@end

@implementation MainTableBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initTabBar];
    [self addChildVC];
}


// 初始化一些设置
- (void)initTabBar
{
    
}

// 添加子控制器
- (void)addChildVC
{
    // 首页
    HomePageViewController *homePageVC = [[HomePageViewController alloc] init];
    [self setupChildViewControllers:homePageVC titleName:kHomeTitle seletedImage:@"icon_tabbar_merchant_selected" normalImage:@"icon_tabbar_merchant_normal"];
    
    // 发现
    DiscoveryViewController *discoverVC = [[DiscoveryViewController alloc] init];
    [self setupChildViewControllers:discoverVC titleName:kDiscovery seletedImage:@"icon_tabbar_onsite_selected" normalImage:@"icon_tabbar_onsite"];
    
    // 新闻
    NewsViewController *newsVC = [[NewsViewController alloc] init];
    [self setupChildViewControllers:newsVC titleName:kNews seletedImage:@"icon_tabbar_misc_selected" normalImage:@"icon_tabbar_misc"];
    
    // 我的
    MineViewController *mineVC = [[MineViewController alloc] init];
    [self setupChildViewControllers:mineVC titleName:kMine seletedImage:@"icon_tabbar_mine_selected" normalImage:@"icon_tabbar_mine"];
    
}

- (void)setupChildViewControllers:(UIViewController *)childController titleName:(NSString *)title seletedImage:(NSString *)slectedImage normalImage:(NSString *)normalImage
{
    BaseNavViewController *nav = [[BaseNavViewController alloc] initWithRootViewController:childController];
    // 禁用图片渲染 如果不加这句话，那么会把选中图片渲染成统一的蓝色
    nav.tabBarItem.selectedImage = [[UIImage imageNamed:slectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置文字的样式
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]} forState:UIControlStateNormal];
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : MainColorHealthyRed} forState:UIControlStateSelected];
    
    nav.title = title;
    nav.tabBarItem.image = [UIImage imageNamed:normalImage];
    [self addChildViewController:nav];
}

@end
